<!--#@embedLayout()-->
#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="certUseDetailList"></div>

        <div id="certUsedatagridTb">
            <div class="row">
                <form id="formId">
                    <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                         data-options="iconCls:'icon-application_form'">

                        开始时间: <input class="easyui-datebox" id="startTime" data-options="required:true,editable:false"
                                     style="width:100px">&nbsp;&nbsp;
                        结束时间: <input class="easyui-datebox" id="endTime" data-options="required:true,editable:false"
                                     style="width:100px">&nbsp;&nbsp;

                        手机盾种类：
                        <select name="secureLevel" id="secureLevel" class="easyui-combobox" data-options="editable: false">
                            <option value="1" selected>专业版</option>
                            <option value="3">标准版</option>
                        </select>&nbsp;&nbsp;

                        用户编号: <input class="easyui-textbox" id="custNo"
                                   style="width:100px">&nbsp;&nbsp;

                        渠道: <input class="easyui-textbox" id="tenantId"
                                   style="width:100px">&nbsp;&nbsp;

                        #if(permissions == "2")
                            机构号: <input class="easyui-textbox" id="instCode"
                                       style="width:100px">&nbsp;&nbsp;
                        #end


                        <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                        <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="$('#formId').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        #if(permissions == "2")
                           <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="datagridExport();" iconCls="icon-print">导出</a>
                        #end
                    </div>
                </form>
                <div class="easyui-panel"  style="width:100%;padding:5px;"
                     data-options="iconCls:'icon-application_form'">
                    &nbsp; 统计结果：<input class="text" id="staCount"
                                       style="width:60px;height: 25px; border:0px;" disabled="disabled">&nbsp;户
                </div>
            </div>
        </div>
    </div>
</div>

#end


#define css()


#end


#define js()

<script type="text/javascript">

    var _datagrid = "certUseDetailList", _form = "formId", _datagridTb = "certUsedatagridTb";
    var datagridListUrl = contextRootPath + '/servicePlugin/certUseDetailListSearch';

    $(function () {

        // 初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 20,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            onLoadSuccess: function (data) {
                //$(".datagrid-htable").css({"height": "50px"});
                //$(".datagrid-htable tbody").prepend("<tr><td>斯蒂芬斯蒂芬</td></tr>");
                //$(".pagination-info").prepend("<span style='color:red;margin-right:15px;'> " + data.total + " 户</span>&nbsp;&nbsp;&nbsp;");
                $("#staCount").val(data.total);
            },
            columns: [[
                {
                    field: DBConts.TABLE_AUTHENTICATORS.CUST_NO,
                    title: "用户编号"
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.INST_CODE,
                    title: "机构号"
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.TENANT_ID,
                    title: "渠道"
                },
                {
                    field: DBConts.TABLE_AUTHENTICATORS.AUTH_TYPE,
                    title: "认证方式",
                    formatter: function (value, row, index) {
                        var auth_type = row.auth_type;
                        //console.log("auth_type:" +auth_type);
                        //debugger;
                        var result;
                        if (auth_type === '20') {
                            result = "<span>证书指纹</span>";
                        }
                        if (auth_type === '21'){
                            result = "<span>证书PIN码</span>";
                        }
                        if (auth_type === '22'){
                            result = "<span>证书人脸</span>";
                        }
                        return result;
                    }
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_ID,
                    title: "设备标识"
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_NAME,
                    title: '设备型号/版本号'
                },
                {
                    field: DBConts.TABLE_DEVICES.OS_VERSION,
                    title: '系统版本'
                },
                {
                    field: DBConts.TABLE_DEVICES.OS_TYPE,
                    title: '系统类型'
                },
                {
                    field: DBConts.TABLE_DEVICES.DEVICE_TYPE,
                    title: '设备厂商'
                },
                {
                    field: 'createts',
                    title: "开通时间"
                }
            ]]
        });
    });


    // 根据条件查询, 然后重新加载表格
    function datagridQuery() {
        var flag = $("#formId").form('enableValidation').form('validate');
        if (!flag) {
            $.messager.alert("提示", "请选择查询的时间段！");
            return;
        }

        $("#" + _datagrid).datagrid({
            queryParams: {
                'secure_level': $('#secureLevel').val(),
                'authenticators.tenant_id':$('#tenantId').val(),
                'start_time':$('#startTime').val(),
                'end_time':$('#endTime').val(),
                'inst_code':$('#instCode').val(),
                'cust_no':$('#custNo').val()
            }
        });
    }


    // 导出Excel
    function datagridExport() {

        #if(permissions == "1")
            $.messager.alert("警告", "权限不够，无法导出！");
            return;
        #end

        var flag = $("#formId").form('enableValidation').form('validate');
        if (!flag) {
            $.messager.alert("提示", "请选择查询的时间段！");
            return;
        }

        $.messager.confirm('确认', "请确认是否导出？", function(r){
            // 进度条开始 interval:1000 是 10秒
            $.messager.progress({ interval: 1000 ,  title: '请等待',  msg: '导出中..........' });

            var params = {
                'secure_level': $('#secureLevel').val(),
                'authenticators.tenant_id':$('#tenantId').val(),
                'start_time':$('#startTime').val(),
                'end_time':$('#endTime').val(),
                'inst_code':$('#instCode').val(),
                'cust_no':$('#custNo').val()
            };

            //console.log(start_time);

            $.post(contextRootPath + "/servicePlugin/certUseDetailListExport", params, function (data) {
                var params = {};
                params.element = _datagrid;
                params.data = data;
                params.isClose = false;
                //console.log(data.exportFileName);
                if(data.exportFileName != null){
                    // 进度条关闭
                    $.messager.progress('close');

                    $.messager.confirm('确认', data.message, function(r){
                        if (r){
                            if(data.exportFileName != null){
                                // 将导出的文件进行下载
                                window.location.href = contextRootPath +"/servicePlugin/exportExcelDownload?fileName=" + data.exportFileName;
                            }else{
                                $.messager.alert('提示','导出文件下载失败！');
                            }
                        }
                    });
                }else {
                    // 进度条关闭
                    $.messager.progress('close');
                    resultCallback(params);
                }
            }, 'json');
        });
    }


</script>

#end
